package com.wxxymaker.edu.controller;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.PostRoute;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.edu.model.entity.User;
import com.wxxymaker.edu.roles.StudentRoles;
import com.wxxymaker.edu.service.TestPaperService;
import com.wxxymaker.edu.utils.TokenUtils;
import io.github.biezhi.anima.page.Page;

/**
 * @AUTHOR soft
 * @DATE 2018/10/11 23:28
 * @DESCRIBE
 */
@StudentRoles
@Path(value = "/course/paper/api", restful = true)
public class TestPaperHandler {
    @Inject
    private TestPaperService testPaperService;

    @PostRoute("/:kid/page")
    public RestResponse page(@PathParam Integer kid,
                             @Param(defaultValue = "1") int page,
                             @Param(defaultValue = "10") int size) {
        User user = TokenUtils.currentUser();
        Page paperPage = testPaperService.page(kid, user.getId(), page, size);
        if (paperPage != null) {
            return RestResponse.ok(paperPage);
        }
        return RestResponse.fail();
    }


}
